package com.example.aop.controller;

import com.example.aop.annotation.LogASP;
import com.example.aop.annotation.TestAnnotation;
import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.OperatingSystem;
import eu.bitwalker.useragentutils.UserAgent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/8/31 14:59
 */
@RestController
public class TestController
{
    @GetMapping("/{name}")
    @LogASP(param = "testAop")
    public String testAop(@PathVariable String name)
    {
        return "Hello " + name;
    }

    @TestAnnotation("this is test1")
    @GetMapping("test1")
    public void test1()
    {
        System.out.println("this is TestService.test1()");
    }

    @TestAnnotation(value = "this is another test2", description = "this is description")
    @GetMapping("test2")
    public void test2()
    {
        System.out.println("this is TestService.test2()");
    }

    @GetMapping("test3")
    public void test3(HttpServletRequest request)
    {
        String agent = request.getHeader("User-Agent");
        //解析agent字符串
        UserAgent userAgent = UserAgent.parseUserAgentString(agent);
        //获取浏览器对象
        Browser browser = userAgent.getBrowser();
        //获取操作系统对象
        OperatingSystem operatingSystem = userAgent.getOperatingSystem();

        System.out.println("浏览器名:" + browser.getName());
        System.out.println("浏览器类型:" + browser.getBrowserType());
        System.out.println("浏览器家族:" + browser.getGroup());
        System.out.println("浏览器生产厂商:" + browser.getManufacturer());
        System.out.println("浏览器使用的渲染引擎:" + browser.getRenderingEngine());
        System.out.println("浏览器版本:" + userAgent.getBrowserVersion());

        System.out.println("操作系统名:" + operatingSystem.getName());
        System.out.println("访问设备类型:" + operatingSystem.getDeviceType());
        System.out.println("操作系统家族:" + operatingSystem.getGroup());
        System.out.println("操作系统生产厂商:" + operatingSystem.getManufacturer());
    }
}
